home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / pascal < prev    next >
Text File  |  1995-11-20  |  3KB  |  77 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Pascal matrix.
  4.  
  5. // Syntax:    P = pascal ( N )
  6.  
  7. // Description:
  8.  
  9. //    The Pascal matrix of order N: a symmetric positive definite
  10. //    matrix with integer entries taken from Pascal's triangle. The
  11. //    Pascal matrix is totally positive and its inverse has integer
  12. //    entries.  Its eigenvalues occur in reciprocal pairs. COND(P)
  13. //    is approximately 16^N/(N*PI) for large N. PASCAL(N,1) is the
  14. //    lower triangular Cholesky factor (up to signs of columns) of
  15. //    the Pascal matrix.   It is involutary (is its own
  16. //    inverse). PASCAL(N,2) is a transposed and permuted version of
  17. //    PASCAL(N,1) which is a cube root of the identity.
  18.  
  19. //      References:
  20. //      R. Brawer and M. Pirovino, The linear algebra of the Pascal matrix,
  21. //           Linear Algebra and Appl., 174 (1992), pp. 13-23 (this paper
  22. //           gives a factorization of L = PASCAL(N,1) and a formula for the
  23. //           elements of L^k).
  24. //      S. Karlin, Total Positivity, Volume 1, Stanford University Press,
  25. //           1968.  (Page 137: shows i+j-1 choose j is TP (i,j=0,1,...).
  26. //                   PASCAL(N) is a submatrix of this matrix.)
  27. //      M. Newman and J. Todd, The evaluation of matrix inversion programs,
  28. //           J. Soc. Indust. Appl. Math., 6(4):466--476, 1958.
  29. //      H. Rutishauser, On test matrices, Programmation en Mathematiques
  30. //           Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165,
  31. //           1966, pp. 349-365.  (Gives an integral formula for the
  32. //           elements of PASCAL(N).)
  33. //      J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
  34. //           Birkhauser, Basel, and Academic Press, New York, 1977, p. 172.
  35. //      H.W. Turnbull, The Theory of Determinants, Matrices, and Invariants,
  36. //           Blackie, London and Glasgow, 1929.  (PASCAL(N,2) on page 332.)
  37.  
  38. //    This file is a translation of pascal.m from version 2.0 of
  39. //    "The Test Matrix Toolbox for Matlab", described in Numerical
  40. //    Analysis Report No. 237, December 1993, by N. J. Higham.
  41.  
  42. //      Dependencies
  43.         require rot90
  44.  
  45. //-------------------------------------------------------------------//
  46.  
  47. pascal = function ( n , k )
  48. {
  49.   local (n, k)
  50.  
  51.   if (!exist (k)) { k = 0; }
  52.  
  53.   P = diag( (-1).^[0:n-1] );
  54.   P[; 1] = ones(n,1);
  55.  
  56.   //  Generate the Pascal Cholesky factor (up to signs).
  57.  
  58.   for (j in 2:n-1)
  59.   {
  60.     for (i in j+1:n)
  61.     {
  62.       i j
  63.       P[i;j] = P[i-1;j] - P[i-1;j-1];
  64.     }
  65.   }
  66.  
  67.   if (k == 0)
  68.   {
  69.     P = P*P';
  70.   else if (k == 2) {
  71.     P = rot90(P,3);
  72.     if (n/2 == round(n/2)) { P = -P; }
  73.   }}
  74.  
  75.   return P;
  76. };
  77.